import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False
data = pd.read_excel('某地区上半年空气质量指数.xlsx')
fig = plt.figure(figsize=(20, 12))
fig1 = plt.subplot(2, 3, 1)
fig2 = plt.subplot(2, 3, 2)
fig3 = plt.subplot(2, 3, 3)
fig4 = plt.subplot(2, 3, 4)
fig5 = plt.subplot(2, 3, 5)
fig6 = plt.subplot(2, 3, 6)
fig1.scatter(data['PM2.5'], data['空气质量指数（AQI）'], color='b', alpha=0.6)
fig1.set_title('PM2.5与AQI的关系')
fig1.set_xlabel('PM2.5含量')
fig1.set_ylabel('空气质量指数（AQI）')
fig2.scatter(data['PM10'], data['空气质量指数（AQI）'], color='g', alpha=0.6)
fig2.set_title('PM10与AQI的关系')
fig2.set_xlabel('PM10含量')
fig2.set_ylabel('空气质量指数（AQI）')
fig3.scatter(data['SO2'], data['空气质量指数（AQI）'], color='r', alpha=0.6)
fig3.set_title('SO2与AQI的关系')
fig3.set_xlabel('SO2含量')
fig3.set_ylabel('空气质量指数（AQI）')
fig4.scatter(data['CO'], data['空气质量指数（AQI）'], color='y', alpha=0.6)
fig4.set_title('CO与AQI的关系')
fig4.set_xlabel('CO含量')
fig4.set_ylabel('空气质量指数（AQI）')
fig5.scatter(data['NO2'], data['空气质量指数（AQI）'], color='purple', alpha=0.6)  # 更改颜色避免与SO2重复
fig5.set_title('NO2与AQI的关系')
fig5.set_xlabel('NO2含量')
fig5.set_ylabel('空气质量指数（AQI）')
fig6.scatter(data['O3'], data['空气质量指数（AQI）'], color='orange', alpha=0.6)  # 更改颜色避免与SO2重复
fig6.set_title('O3与AQI的关系')
fig6.set_xlabel('O3含量')
fig6.set_ylabel('空气质量指数（AQI）')
plt.subplots_adjust(hspace=0.3, wspace=0.2)
plt.show()